package com.xnfh.common.provider

import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.launcher.ARouter
import com.xnfh.common.constant.ArouterPath
import com.xnfh.common.service.ILoginService

/**
 * @Description:任意模块就能通过LoginServiceProvider使用对外暴露的能力
 * @Author: ziheng
 * @CreateDate: 2023/11/8 10:01
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/11/8 10:01
 * @UpdateRemark: 更新说明
 */
object LoginServiceProvider {

    @Autowired(name = ArouterPath.SERVICE.LOGIN_SERVICE)
    lateinit var loginService: ILoginService

    init {
        ARouter.getInstance().inject(this)
    }

    /**
     * 是否登录
     * @return Boolean
     */
    fun isLogin(): Boolean {
        return loginService.isLogin()
    }

    /**
     * 跳转登录页
     * @param context
     */
    fun login(context: Context) {
        loginService.login(context)
    }

    /**
     * 跳转隐私协议
     * @param context
     */
    fun readPolicy(context: Context) {
        loginService.readPolicy(context)
    }

    /**
     * 登出
     * @param context
     * @param lifecycleOwner
     * @param observer
     */
    fun logout(
        context: Context,
        lifecycleOwner: LifecycleOwner?,
        observer: Observer<Boolean>
    ) {
        loginService.logout(context, lifecycleOwner, observer)
    }

}